

import sys
def prettyprint_lxml(src=None):
    from lxml.etree import parse
    from lxml.etree import tostring
    if src is None:
        src=sys.stdin

    x = parse(src)
    return tostring(x,pretty_print=True).decode('utf-8')

def prettyprint_minidom(src=None):
    from xml.dom.minidom import parse
    if src is None:
        src=sys.stdin
    xml_obj = parse(src) # or xml.dom.minidom.parseString(xml_string)
    return xml_obj.toprettyxml()
def prettyprint_bs4(src=None):
    if src is None:
        src=sys.stdin
    from bs4 import BeautifulSoup
    soup = BeautifulSoup(src,'html.parser')

    return soup.prettify()
def prettyprint_xml(src=None):

    if src is None:
        src=sys.stdin

    from xml.etree import ElementTree

    def indent(elem, level=0):
        i = "\n" + level*"  "
        j = "\n" + (level-1)*"  "
        if len(elem):
            if not elem.text or not elem.text.strip():
                elem.text = i + "  "
            if not elem.tail or not elem.tail.strip():
                elem.tail = i
            for subelem in elem:
                indent(subelem, level+1)
            if not elem.tail or not elem.tail.strip():
                elem.tail = j
        else:
            if level and (not elem.tail or not elem.tail.strip()):
                elem.tail = j
                #~ elem.text = repr(elem.text) if type(elem.text) is not str else repr(elem.text.strip())
        return elem

    root = ElementTree.parse(src).getroot()
    indent(root)
    return ElementTree.tostring(root).decode('utf-8')

prettyprint=prettyprint_xml
if __name__ == '__main__':
    if len(sys.argv) ==1:
        print(prettyprint(sys.stdin))
        sys.exit(0)
    prettyprint(sys.argv[1])
    sys.exit(0)


